home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / winsrc17.zip / CMDFILES.C < prev    next >
Text File  |  1992-01-15  |  61KB  |  1,957 lines

  1. /*
  2.     Command-line / Command-File Parser Routines
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <float.h>
  10. #include <ctype.h>
  11. #include "fractint.h"
  12. #ifdef __TURBOC__
  13. #include <dir.h>
  14. #endif
  15.  
  16. /* routines in this module    */
  17.  
  18. void cmdfiles_overlay(void);
  19. int  cmdfiles(int argc, char *argv[]);
  20. int  load_commands(FILE *);
  21. void set_3d_defaults(void);
  22.  
  23. static int  cmdfile(FILE *,int);
  24. static int  next_command(char *,int,FILE *,char *,int *,int);
  25. static int  next_line(FILE *,char *,int);
  26. static int  cmdarg(char *,int);
  27. static void argerror(char *);
  28. static void initvars_run(void);
  29. static void initvars_restart(void);
  30. static void initvars_fractal(void);
  31. static void initvars_3d(void);
  32. static void reset_ifs_defn(void);
  33. static void parse_textcolors(char *value);
  34. static int  parse_colors(char *value);
  35. static int  parse_printer(char *value);
  36.  
  37. extern int  makedoc_msg_func(int,int);
  38.  
  39. /* variables defined by the command line/files processor */
  40. int        showdot;    /* color to show crawling graphics cursor */
  41. char    temp1[256];        /* temporary strings        */
  42. char    readname[80];        /* name of fractal input file */
  43. char    gifmask[13] = {""};
  44. char    PrintName[80]={"fract001.prn"}; /* Name for print-to-file */
  45. char    savename[80]={"fract001"};      /* save files using this name */
  46. char    autoname[80]={"auto.key"};      /* record auto keystrokes here */
  47. int    potflag=0;        /* continuous potential enabled? */
  48. int    pot16bit;        /* store 16 bit continuous potential values */
  49. int    gif87a_flag;        /* 1 if GIF87a format, 0 otherwise */
  50. int    askvideo;        /* flag for video prompting */
  51. char    floatflag;
  52. int    biomorph;        /* flag for biomorph */
  53. int    usr_biomorph;
  54. int    forcesymmetry;        /* force symmetry */
  55. int    showfile;        /* zero if file display pending */
  56. int    rflag, rseed;        /* Random number seeding flag and value */
  57. int    decomp[2];        /* Decomposition coloring */
  58. int    distest;
  59. int    distestwidth;
  60. char overwrite = 0;    /* 0 if file overwrite not allowed */
  61. int    soundflag;        /* 0 if sound is off, 1 if on */
  62. int    basehertz;        /* sound=x/y/x hertz value */
  63. int    debugflag;        /* internal use only - you didn't see this */
  64. int    timerflag;        /* you didn't see this, either */
  65. int    cyclelimit;        /* color-rotator upper limit */
  66. int    inside;         /* inside color: 1=blue     */
  67. int    fillcolor;         /* fillcolor: -1=normal     */
  68. int    outside;        /* outside color    */
  69. int    finattract;        /* finite attractor logic */
  70. int    display3d;        /* 3D display flag: 0 = OFF */
  71. int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  72. int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  73. int    initbatch;        /* 1 if batch run (no kbd)  */
  74. unsigned initsavetime;        /* autosave minutes        */
  75. double    initorbit[2];        /* initial orbitvalue */
  76. char    useinitorbit;        /* flag for initorbit */
  77. int    initmode;        /* initial video mode        */
  78. int    initcyclelimit;     /* initial cycle limit        */
  79. unsigned char usemag;        /* use center-mag corners   */
  80. int    bailout;        /* user input bailout value */
  81. double    inversion[3];        /* radius, xcenter, ycenter */
  82. int    rotate_lo,rotate_hi;    /* cycling color range        */
  83. int far *ranges;        /* iter->color ranges mapping */
  84. int    rangeslen = 0;        /* size of ranges array     */
  85. char far *mapdacbox = NULL;    /* map= (default colors)    */
  86. int    colorstate;        /* 0, dacbox matches default (bios or map=) */
  87.                 /* 1, dacbox matches no known defined map   */
  88.                 /* 2, dacbox matches the colorfile map        */
  89. int    colorpreloaded;     /* if dacbox preloaded for next mode select */
  90. extern int Targa_Overlay;
  91. int Targa_Out = 0;
  92. char    colorfile[80];        /* from last <l> <s> or colors=@filename    */
  93.  
  94. /* TARGA+ variables */
  95. int    TPlusFlag;        /* Use the TARGA+ if found  */
  96. int    MaxColorRes;        /* Default Color Resolution if available */
  97. int    PixelZoom;        /* TPlus Zoom Level */
  98. int    NonInterlaced;        /* Non-Interlaced video flag */
  99.  
  100. /* 3D Transparency Variables, MCP 5-30-91 */
  101. double xcoord, ycoord, zcoord, tcoord;
  102. double zzmin, zzmax;        /* initial depth corner values */
  103. double ttmin, ttmax;        /* initial time coordinates */
  104. int Transparent3D, SolidCore, MultiDrawing;
  105. int tpdepth, tptime;
  106. unsigned CoreRed, CoreGreen, CoreBlue, NumFrames;
  107.  
  108. /* AntiAliasing variables, MCP 6-6-91 */
  109. int AntiAliasing, Shadowing;
  110.  
  111. int    orbitsave = 0;        /* for IFS and LORENZ to output acrospin file */
  112. int orbit_delay;                /* clock ticks delating orbit release */
  113. extern    int invert;
  114. extern int fractype;        /* fractal type         */
  115. extern double param[4];     /* initial parameters        */
  116. extern double xxmin,xxmax;    /* initial corner values    */
  117. extern double yymin,yymax;    /* initial corner values    */
  118. extern double xx3rd,yy3rd;    /* initial corner values    */
  119. extern char usr_stdcalcmode;    /* '1', '2', 'g', 'b'       */
  120. extern int maxit;        /* max iterations        */
  121. extern int usr_periodicitycheck; /* periodicity checking  1=on,0=off */
  122. extern char usr_floatflag;    /* flag for float calcs */
  123. extern int usr_distest;     /* nonzero if distance estimator option */
  124. extern char color_lakes;    /* finite attractor flag */
  125. extern int haze;
  126. extern int RANDOMIZE;
  127. extern int Ambient;
  128. extern char light_name[];
  129. extern int BRIEF;
  130. extern int RAY;
  131.  
  132. extern unsigned char back_color[];
  133. extern unsigned char dacbox[256][3];
  134. extern struct videoinfo far videotable[];
  135. extern int fpu;
  136. extern int iit;
  137.  
  138. extern double potparam[];    /* potential parameters  */
  139. extern int Printer_Resolution, LPTNumber,
  140.        Printer_Type, Printer_Titleblock,
  141.        Printer_ColorXlat, Printer_SetScreen,
  142.        Printer_SFrequency, Printer_SAngle, Printer_SStyle,
  143.        Printer_RFrequency, Printer_RAngle, Printer_RStyle,
  144.        Printer_GFrequency, Printer_GAngle, Printer_GStyle,
  145.        Printer_BFrequency, Printer_BAngle, Printer_BStyle,
  146.        EPSFileType, ColorPS,
  147.        Print_To_File,Printer_CRLF;        /* for printer functions */
  148.  
  149. int    transparent[2];     /* transparency min/max values */
  150. int    LogFlag;        /* Logarithmic palette flag: 0 = no */
  151.  
  152. unsigned char exitmode = 3;    /* video mode on exit */
  153.  
  154. extern int video_type;
  155. extern int svga_type;           /* for forcing a specific SVGA adapter */
  156. extern int mode7text;
  157. extern int textsafe;
  158. extern int vesa_detect;
  159.  
  160. int        bios_palette;        /* set to 1 to force BIOS palette updates */
  161. int        escape_exit;         /* set to 1 to avoid the "are you sure?" screen */
  162.  
  163. extern int   viewwindow;
  164. extern float viewreduction;
  165. extern int   viewcrop;
  166. extern float finalaspectratio;
  167. extern int   viewxdots,viewydots;
  168.  
  169. extern char MAP_name[];
  170. extern int mapset;
  171.  
  172. extern int eyeseparation; /* Occular Separation */
  173. extern int glassestype;
  174. extern int xadjust; /* Convergence */
  175. extern int yadjust;
  176. extern int xtrans, ytrans; /* X,Y shift with no perspective */
  177. extern int red_crop_left, red_crop_right;
  178. extern int blue_crop_left, blue_crop_right;
  179. extern int red_bright, blue_bright;
  180. extern char showbox; /* flag to show box and vector in preview */
  181. extern char preview;        /* 3D preview mode flag */
  182. extern int previewfactor; /* Coarsness */
  183.  
  184. int first_init=1;        /* first time into cmdfiles? */
  185. static int init_rseed;
  186. static char initcorners,initparams;
  187. struct fractalspecificstuff far *curfractalspecific;
  188.  
  189. char FormFileName[80];        /* file to find (type=)formulas in */
  190. char FormName[ITEMNAMELEN+1];    /* Name of the Formula (if not null) */
  191. char LFileName[80];        /* file to find (type=)L-System's in */
  192. char LName[ITEMNAMELEN+1];    /* Name of L-System */
  193. char CommandFile[80];        /* file to find command sets in */
  194. char CommandName[ITEMNAMELEN+1];/* Name of Command set */
  195. char CommandComment1[57];    /* comments for command set */
  196. char CommandComment2[57];
  197. char IFSFileName[80];        /* file to find (type=)IFS in */
  198. char IFSName[ITEMNAMELEN+1];    /* Name of the IFS def'n (if not null) */
  199. float far *ifs_defn = NULL;    /* ifs parameters */
  200. int  ifs_changed;        /* nonzero if parameters have been edited */
  201. int  ifs_type;            /* 0=2d, 1=3d */
  202. int  slides = 0;        /* 1 autokey=play, 2 autokey=record */
  203.  
  204. unsigned char txtcolor[]={
  205.       BLUE*16+L_WHITE,      /* C_TITLE           title background */
  206.       BLUE*16+L_GREEN,      /* C_TITLE_DEV       development vsn foreground */
  207.       GREEN*16+YELLOW,      /* C_HELP_HDG        help page title line */
  208.       WHITE*16+BLACK,      /* C_HELP_BODY       help page body */
  209.       GREEN*16+GRAY,      /* C_HELP_INSTR      help page instr at bottom */
  210.       WHITE*16+BLUE,      /* C_HELP_LINK       help page links */
  211.       CYAN*16+BLUE,      /* C_HELP_CURLINK    help page current link */
  212.       WHITE*16+GRAY,      /* C_PROMPT_BKGRD    prompt/choice background */
  213.       WHITE*16+BLACK,      /* C_PROMPT_TEXT     prompt/choice extra info */
  214.       BLUE*16+WHITE,      /* C_PROMPT_LO       prompt/choice text */
  215.       BLUE*16+L_WHITE,      /* C_PROMPT_MED      prompt/choice hdg2/... */
  216.       BLUE*16+YELLOW,      /* C_PROMPT_HI       prompt/choice hdg/cur/... */
  217.       GREEN*16+L_WHITE,   /* C_PROMPT_INPUT    fullscreen_prompt input */
  218.       CYAN*16+L_WHITE,      /* C_PROMPT_CHOOSE   fullscreen_prompt choice */
  219.       MAGENTA*16+L_WHITE, /* C_CHOICE_CURRENT  fullscreen_choice input */
  220.       BLACK*16+WHITE,      /* C_CHOICE_SP_INSTR speed key bar & instr */
  221.       BLACK*16+L_MAGENTA, /* C_CHOICE_SP_KEYIN speed key value */
  222.       WHITE*16+BLUE,      /* C_GENERAL_HI      tab, thinking, IFS */
  223.       WHITE*16+BLACK,      /* C_GENERAL_MED */
  224.       WHITE*16+GRAY,      /* C_GENERAL_LO */
  225.       BLACK*16+L_WHITE,   /* C_GENERAL_INPUT */
  226.       WHITE*16+BLACK,      /* C_DVID_BKGRD      disk video */
  227.       BLACK*16+YELLOW,      /* C_DVID_HI */
  228.       BLACK*16+L_WHITE,   /* C_DVID_LO */
  229.       RED*16+L_WHITE,      /* C_STOP_ERR        stop message, error */
  230.       GREEN*16+BLACK,      /* C_STOP_INFO       stop message, info */
  231.       BLUE*16+WHITE,      /* C_TITLE_LOW       bottom lines of title screen */
  232.       GREEN*16+BLACK,      /* C_AUTHDIV1        title screen dividers */
  233.       GREEN*16+GRAY,      /* C_AUTHDIV2        title screen dividers */
  234.       BLACK*16+L_WHITE,   /* C_PRIMARY           primary authors */
  235.       BLACK*16+WHITE      /* C_CONTRIB           contributing authors */
  236.       };
  237.  
  238. extern int active_system;
  239. /* start of string literals cleanup */
  240. char s_iter[]    = "iter";
  241. char s_real[]    = "real";
  242. char s_mult[]     = "mult";
  243. char s_sum[]     = "summ";
  244. char s_imag[]    = "imag";
  245. char s_zmag[]    = "zmag";
  246. char s_bof60[]   = "bof60";
  247. char s_bof61[]   = "bof61";
  248. char s_maxiter[] =  "maxiter";
  249. char s_epscross[] =  "epsilon cross";
  250. char s_startrail[] =  "star trail";
  251. char s_normal[] =  "normal";
  252.  
  253.  
  254. void cmdfiles_overlay() { }    /* for restore_active_ovly */
  255.  
  256. /*
  257.     cmdfiles(argc,argv) process the command-line arguments
  258.         it also processes the 'sstools.ini' file and any
  259.         indirect files ('fractint @myfile')
  260. */
  261.  
  262. int cmdfiles(int argc,char *argv[])
  263. {
  264.    int       i;
  265.    char    curarg[141];
  266.    char    tempstring[101];
  267.    char    *sptr;
  268.    FILE    *initfile;
  269.  
  270.    ENTER_OVLY(OVLY_CMDFILES);
  271.  
  272.    if (first_init) initvars_run();    /* once per run initialization */
  273.    initvars_restart();            /* <ins> key initialization */
  274.    initvars_fractal();            /* image initialization */
  275.  
  276.    findpath("sstools.ini", tempstring); /* look for SSTOOLS.INI */
  277.    if (tempstring[0] != 0)        /* found it! */
  278.       if ((initfile = fopen(tempstring,"r")) != NULL)
  279.      cmdfile(initfile,1);        /* process it */
  280.  
  281.    for (i = 1; i < argc; i++) {     /* cycle through args */
  282.       strcpy(curarg,argv[i]);
  283.       if (curarg[0] == ';')             /* start of comments? */
  284.      break;
  285.       if (curarg[0] != '@') {           /* simple command? */
  286.      if (strchr(curarg,'=') == NULL) { /* not xxx=yyy, so check for gif */
  287.         strcpy(tempstring,curarg);
  288.         if (strchr(curarg,'.') == NULL)
  289.            strcat(tempstring,".gif");
  290.         if ((initfile = fopen(tempstring,"rb"))) {
  291.            fread(tempstring,6,1,initfile);
  292.            if ( tempstring[0] == 'G'
  293.          && tempstring[1] == 'I'
  294.          && tempstring[2] == 'F'
  295.          && tempstring[3] >= '8' && tempstring[3] <= '9'
  296.          && tempstring[4] >= '0' && tempstring[4] <= '9') {
  297.           strcpy(readname,curarg);
  298.           curarg[0] = showfile = 0;
  299.           }
  300.            fclose(initfile);
  301.            }
  302.         }
  303.      if (curarg[0])
  304.         cmdarg(curarg,0);        /* process simple command */
  305.      }
  306.       else if ((sptr = strchr(curarg,'/'))) { /* @filename/setname? */
  307.      *sptr = 0;
  308.      strcpy(CommandFile,&curarg[1]);
  309.      strcpy(CommandName,sptr+1);
  310.      find_file_item(CommandFile,CommandName,&initfile);
  311.      cmdfile(initfile,3);
  312.      }
  313.       else {                /* @filename */
  314.      if ((initfile = fopen(&curarg[1],"r")) == NULL)
  315.         argerror(curarg);
  316.      cmdfile(initfile,0);
  317.      }
  318.       }
  319.  
  320.    if (first_init == 0) {
  321.       initmode = -1; /* don't set video when <ins> key used */
  322.       showfile = 1;  /* nor startup image file            */
  323.       }
  324.  
  325.    first_init = 0;
  326.    EXIT_OVLY;
  327.    return(0);
  328. }
  329.  
  330.  
  331. int load_commands(FILE *infile)
  332. {
  333.    /* when called, file is open in binary mode, positioned at the */
  334.    /* '(' or '{' following the desired parameter set's name       */
  335.    int ret;
  336.    ENTER_OVLY(OVLY_CMDFILES);
  337.    initcorners = initparams = 0; /* reset flags for type= */
  338.    ret = cmdfile(infile,2);
  339.    EXIT_OVLY;
  340.    return ret;
  341. }
  342.  
  343.  
  344. static void initvars_run()        /* once per run init */
  345. {
  346.    init_rseed = (int)time(NULL);
  347. }
  348.  
  349. static void initvars_restart()        /* <ins> key init */
  350. {
  351.    gif87a_flag = 0;            /* turn on GIF89a processing */
  352.    askvideo = 1;            /* turn on video-prompt flag */
  353.    overwrite = 0;            /* don't overwrite           */
  354.    soundflag = -1;            /* sound is on             */
  355.    basehertz = 440;            /* basic hertz rate         */
  356.    initbatch = 0;            /* not in batch mode         */
  357.    initsavetime = 0;            /* no auto-save          */
  358.    initmode = -1;            /* no initial video mode     */
  359.    viewwindow = 0;            /* no view window         */
  360.    viewreduction = 4.2;
  361.    viewcrop = 1;
  362.    finalaspectratio = SCREENASPECT;
  363.    viewxdots = viewydots = 0;
  364.    orbit_delay = 0;                     /* full speed orbits */
  365.    debugflag = 0;            /* debugging flag(s) are off */
  366.    timerflag = 0;            /* timer flags are off         */
  367.    strcpy(FormFileName,"fractint.frm"); /* default formula file      */
  368.    FormName[0] = 0;
  369.    strcpy(LFileName,"fractint.l");
  370.    LName[0] = 0;
  371.    strcpy(CommandFile,"fractint.par");
  372.    CommandName[0] = CommandComment1[0] = CommandComment2[0] = 0;
  373.    strcpy(IFSFileName,"fractint.ifs");
  374.    IFSName[0] = 0;
  375.    reset_ifs_defn();
  376.    rflag = 0;                /* not a fixed srand() seed */
  377.    rseed = init_rseed;
  378.    strcpy(readname,".\\");              /* initially current directory */
  379.    showfile = 1;
  380.    /* next should perhaps be fractal re-init, not just <ins> ? */
  381.    initcyclelimit=55;            /* spin-DAC default speed limit */
  382.    mapset = 0;                /* no map= name active */
  383.    if (mapdacbox) {
  384.       farmemfree(mapdacbox);
  385.       mapdacbox = NULL;
  386.       }
  387.    TPlusFlag = 1;
  388.    MaxColorRes = 8;
  389.    PixelZoom = 0;
  390.    NonInterlaced = 0;
  391.  
  392.    Transparent3D = 0;
  393.    SolidCore = 1;
  394.    CoreRed   = 128;
  395.    CoreGreen = 128;
  396.    CoreBlue  = 128;
  397.    zzmin = -1.5;
  398.    zzmax = 1.5;
  399.    ttmin = 0.0;
  400.    ttmax = 0.0;
  401.    NumFrames = 1;
  402.    tpdepth = tptime = 0;
  403.  
  404.    AntiAliasing = 0;
  405.    Shadowing = 0;
  406.  
  407.    Printer_Type = 2;            /* assume an IBM/EPSON      */
  408.    Printer_Resolution = 60;        /* assume low resolution  */
  409.    Printer_Titleblock = 0;        /* assume no title block  */
  410.    Printer_ColorXlat = 0;        /* assume positive image  */
  411.    Printer_SetScreen = 0;               /* assume default screen  */
  412.    Printer_SFrequency = 45;             /* New screen frequency K */
  413.    Printer_SAngle = 45;                 /* New screen angle     K */
  414.    Printer_SStyle = 1;                  /* New screen style     K */
  415.    Printer_RFrequency = 45;             /* New screen frequency R */
  416.    Printer_RAngle = 75;                 /* New screen angle     R */
  417.    Printer_RStyle = 1;                  /* New screen style     R */
  418.    Printer_GFrequency = 45;             /* New screen frequency G */
  419.    Printer_GAngle = 15;                 /* New screen angle     G */
  420.    Printer_GStyle = 1;                  /* New screen style     G */
  421.    Printer_BFrequency = 45;             /* New screen frequency B */
  422.    Printer_BAngle = 0;                  /* New screen angle     B */
  423.    Printer_BStyle = 1;                  /* New screen style     B */
  424.    Print_To_File = 0;            /* No print-to-file      */
  425.    Printer_CRLF = 0;            /* Assume CR+LF       */
  426.    EPSFileType = 0;            /* Assume no save to .EPS */
  427.    LPTNumber = 1;            /* assume LPT1 */
  428.    ColorPS = 0;                         /* Assume NO Color PostScr*/
  429.  
  430. }
  431.  
  432. static void initvars_fractal()        /* init vars affecting calculation */
  433. {
  434.    int i;
  435.    bios_palette = 0;                    /* don't force use of a BIOS palette */
  436.    escape_exit = 0;                     /* don't disable the "are you sure?" screen */
  437.    usr_periodicitycheck = 1;        /* turn on periodicity      */
  438.    inside = 1;                /* inside color = blue      */
  439.    fillcolor = -1;            /* no special fill color */
  440.    usr_biomorph = -1;            /* turn off biomorph flag */
  441.    outside = -1;            /* outside color = -1 (not used) */
  442.    maxit = 150;             /* initial maxiter      */
  443.    usr_stdcalcmode = 'g';               /* initial solid-guessing */
  444.    usr_floatflag = 0;            /* turn off the float flag */
  445.    finattract = 0;            /* disable finite attractor logic */
  446.    fractype = 0;            /* initial type Set flag  */
  447.    curfractalspecific = &fractalspecific[0];
  448.    initcorners = initparams = 0;
  449.    bailout = 0;             /* no user-entered bailout */
  450.    useinitorbit = 0;
  451.    for (i = 0; i < 4; i++) param[i] = 0.0;     /* initial parameter values */
  452.    for (i = 0; i < 3; i++) potparam[i]    = 0.0; /* initial potential values */
  453.    for (i = 0; i < 3; i++) inversion[i] = 0.0;    /* initial invert values */
  454.    initorbit[0] = initorbit[1] = 0.0;    /* initial orbit values */
  455.    invert = 0;
  456.    decomp[0] = decomp[1] = 0;
  457.    usr_distest = 0;
  458.    distestwidth = 71;
  459.    forcesymmetry = 999;         /* symmetry not forced */
  460.    xx3rd = xxmin = -2.5; xxmax = 1.5;    /* initial corner values  */
  461.    yy3rd = yymin = -1.5; yymax = 1.5;    /* initial corner values  */
  462.    pot16bit = potflag = 0;
  463.    LogFlag = 0;             /* no logarithmic palette */
  464.    set_trig_array(0,"sin");             /* trigfn defaults */
  465.    set_trig_array(1,"sqr");
  466.    set_trig_array(2,"sinh");
  467.    set_trig_array(3,"cosh");
  468.    if (rangeslen) {
  469.       farmemfree((char far *)ranges);
  470.       rangeslen = 0;
  471.       }
  472.    usemag = 0;                /* use corners, not center-mag */
  473.  
  474.    colorstate = colorpreloaded = 0;
  475.    rotate_lo = 1; rotate_hi = 255;    /* color cycling default range */
  476.  
  477.    display3d = 0;            /* 3D display is off        */
  478.    overlay3d = 0;            /* 3D overlay is off        */
  479.  
  480.    initvars_3d();
  481. }
  482.  
  483. static void initvars_3d()        /* init vars affecting 3d */
  484. {
  485.    RAY     = 0;
  486.    BRIEF   = 0;
  487.    SPHERE = FALSE;
  488.    preview = 0;
  489.    showbox = 0;
  490.    xadjust = 0;
  491.    yadjust = 0;
  492.    eyeseparation = 0;
  493.    glassestype = 0;
  494.    previewfactor = 20;
  495.    red_crop_left   = 4;
  496.    red_crop_right  = 0;
  497.    blue_crop_left  = 0;
  498.    blue_crop_right = 4;
  499.    red_bright      = 80;
  500.    blue_bright     = 100;
  501.    transparent[0] = transparent[1] = 0; /* no min/max transparency */
  502.    set_3d_defaults();
  503. }
  504.  
  505. static void reset_ifs_defn()
  506. {
  507.    if (ifs_defn) {
  508.       farmemfree((char far *)ifs_defn);
  509.       ifs_defn = NULL;
  510.       }
  511. }
  512.  
  513.  
  514. static int cmdfile(FILE *handle,int mode)
  515.    /* mode = 0 command line @filename          */
  516.    /*         1 sstools.ini              */
  517.    /*         2 <@> command after startup      */
  518.    /*         3 command line @filename/setname */
  519. {
  520.    /* note that cmdfile could be open as text OR as binary */
  521.    /* binary is used in @ command processing for reasonable speed note/point */
  522.    int i;
  523.    int lineoffset = 0;
  524.    int changeflag = 0; /* &1 fractal stuff chgd, &2 3d stuff chgd */
  525.    char linebuf[513],cmdbuf[1001];
  526.    if (mode == 2 || mode == 3) {
  527.       while ((i = getc(handle)) != '{' && i != EOF) { }
  528.       CommandComment1[0] = CommandComment2[0] = 0;
  529.       }
  530.    linebuf[0] = 0;
  531.    while (next_command(cmdbuf,1000,handle,linebuf,&lineoffset,mode) > 0) {
  532.       if ((mode == 2 || mode == 3) && strcmp(cmdbuf,"}") == 0) break;
  533.       if ((i = cmdarg(cmdbuf,mode)) < 0) break;
  534.       changeflag |= i;
  535.       }
  536.    fclose(handle);
  537.    return changeflag;
  538. }
  539.  
  540. static int next_command(char *cmdbuf,int maxlen,
  541.               FILE *handle,char *linebuf,int *lineoffset,int mode)
  542. {
  543.    int cmdlen = 0;
  544.    char *lineptr;
  545.    lineptr = linebuf + *lineoffset;
  546.    while(1) {
  547.       while (*lineptr <= ' ' || *lineptr == ';') {
  548.      if (cmdlen) {            /* space or ; marks end of command */
  549.         cmdbuf[cmdlen] = 0;
  550.         *lineoffset = lineptr - linebuf;
  551.         return cmdlen;
  552.         }
  553.      while (*lineptr && *lineptr <= ' ')
  554.         ++lineptr;            /* skip spaces and tabs */
  555.      if (*lineptr == ';' || *lineptr == 0) {
  556.         if (*lineptr == ';'
  557.           && (mode == 2 || mode == 3)
  558.           && (CommandComment1[0] == 0 || CommandComment2[0] == 0)) {
  559.            /* save comment */
  560.            while (*(++lineptr)
  561.          && (*lineptr == ' ' || *lineptr == '\t')) { }
  562.            if (*lineptr) {
  563.           if (strlen(lineptr) > 56)
  564.              *(lineptr+56) = 0;
  565.           if (CommandComment1[0] == 0)
  566.              strcpy(CommandComment1,lineptr);
  567.           else
  568.              strcpy(CommandComment2,lineptr);
  569.           }
  570.            }
  571.         if (next_line(handle,linebuf,mode) != 0)
  572.            return(-1); /* eof */
  573.         lineptr = linebuf; /* start new line */
  574.         }
  575.      }
  576.       if (*lineptr == '\\'              /* continuation onto next line? */
  577.     && *(lineptr+1) == 0) {
  578.      if (next_line(handle,linebuf,mode) != 0) {
  579.         argerror(cmdbuf);        /* missing continuation */
  580.         return(-1);
  581.         }
  582.      lineptr = linebuf;
  583.      while (*lineptr && *lineptr <= ' ')
  584.         ++lineptr;            /* skip white space @ start next line */
  585.      continue;            /* loop to check end of line again */
  586.      }
  587.       cmdbuf[cmdlen] = *(lineptr++);    /* copy character to command buffer */
  588.       if (++cmdlen >= maxlen) {     /* command too long? */
  589.      argerror(cmdbuf);
  590.      return(-1);
  591.      }
  592.       }
  593. }
  594.  
  595. static int next_line(FILE *handle,char *linebuf,int mode)
  596. {
  597.    int toolssection;
  598.    char tmpbuf[10];
  599.    toolssection = 0;
  600.    while (file_gets(linebuf,512,handle) >= 0) {
  601.       if (mode == 1 && linebuf[0] == '[') {     /* check for [fractint] */
  602.      strncpy(tmpbuf,&linebuf[1],9);
  603.      tmpbuf[9] = 0;
  604.      strlwr(tmpbuf);
  605.      toolssection = strncmp(tmpbuf,"fractint]",9);
  606.      continue;                /* skip tools section heading */
  607.      }
  608.       if (toolssection == 0) return(0);
  609.       }
  610.    return(-1);
  611. }
  612.  
  613.  
  614. /*
  615.   cmdarg(string,mode) processes a single command-line/command-file argument
  616.     return:
  617.       -1 error, >= 0 ok
  618.       if ok, return value:
  619.     | 1 means fractal parm has been set
  620.     | 2 means 3d parm has been set
  621.     | 4 means 3d=yes specified
  622.     | 8 means reset specified
  623. */
  624.  
  625. static int cmdarg(char *curarg,int mode) /* process a single argument */
  626. {
  627.    char    variable[21];        /* variable name goes here   */
  628.    char    *value;            /* pointer to variable value */
  629.    int       valuelen;            /* length of value         */
  630.    int       numval;            /* numeric value of arg      */
  631. #define NONNUMERIC -32767
  632.    char    charval;            /* first character of arg    */
  633.    int       yesnoval;            /* 0 if 'n', 1 if 'y', -1 if not */
  634.    double  ftemp;
  635.    int       i, j, k, l;
  636.    char    *argptr,*argptr2;
  637.    int       totparms;            /* # of / delimited parms    */
  638.    int       intparms;            /* # of / delimited ints     */
  639.    int       floatparms;            /* # of / delimited floats   */
  640.    int       intval[64];            /* pre-parsed integer parms  */
  641.    double  floatval[16];        /* pre-parsed floating parms */
  642.    char    tmpc;
  643.    int       lastarg;
  644.  
  645.    argptr = curarg;
  646.    while (*argptr) {            /* convert to lower case */
  647.       if (*argptr >= 'A' && *argptr <= 'Z')
  648.      *argptr += 'a' - 'A';
  649.       if (*argptr == '=' && strncmp(curarg,"colors=",7) == 0)
  650.      break;             /* don't convert colors=value */
  651.       ++argptr;
  652.       }
  653.  
  654.    if ((value = strchr(&curarg[1],'='))) {
  655.       if ((j = (value++) - curarg) > 1 && curarg[j-1] == ':')
  656.      --j;                /* treat := same as =      */
  657.       }
  658.    else
  659.       value = curarg + (j = strlen(curarg));
  660.    if (j > 20) goto badarg;        /* keyword too long */
  661.    strncpy(variable,curarg,j);        /* get the variable name  */
  662.    variable[j] = 0;            /* truncate variable name */
  663.    valuelen = strlen(value);        /* note value's length    */
  664.    charval = value[0];            /* first letter of value  */
  665.    yesnoval = -1;            /* note yes|no value      */
  666.    if (charval == 'n') yesnoval = 0;
  667.    if (charval == 'y') yesnoval = 1;
  668.  
  669.    argptr = value;
  670.    numval = totparms = intparms = floatparms = 0;
  671.    while (*argptr) {            /* count and pre-parse parms */
  672.       lastarg = 0;
  673.       if ((argptr2 = strchr(argptr,'/')) == NULL) {     /* find next '/' */
  674.      argptr2 = argptr + strlen(argptr);
  675.      *argptr2 = '/';
  676.      lastarg = 1;
  677.      }
  678.       if (totparms == 0) numval = NONNUMERIC;
  679.       i = -1;
  680.       if (sscanf(argptr,"%d%c",&j,&tmpc) > 0            /* got an integer */
  681.     && tmpc == '/') {
  682.      ++floatparms; ++intparms;
  683.      if (totparms < 16) floatval[totparms] = j;
  684.      if (totparms < 64) intval[totparms] = j;
  685.      if (totparms == 0) numval = j;
  686.      }
  687.       else if (sscanf(argptr,"%lg%c",&ftemp,&tmpc) > 0  /* got a float */
  688.          && tmpc == '/') {
  689.      ++floatparms;
  690.      if (totparms < 16) floatval[totparms] = ftemp;
  691.      }
  692.       ++totparms;
  693.       argptr = argptr2;                 /* on to the next */
  694.       if (lastarg)
  695.      *argptr = 0;
  696.       else
  697.      ++argptr;
  698.       }
  699.  
  700.    if (mode != 2) {    /* these commands are allowed only at startup */
  701.  
  702.       if (strcmp(variable,"batch") == 0 ) {     /* batch=?      */
  703.      if (yesnoval < 0) goto badarg;
  704.      initbatch = yesnoval;
  705.      return 3;
  706.      }
  707.  
  708.       if (strcmp(variable,"adapter") == 0 ) {   /* adapter==?     */
  709.  
  710.          if (strncmp(value,"aheada",6) == 0) svga_type = 1;
  711.          if (strncmp(value,"ati"   ,3) == 0) svga_type = 2;
  712.          if (strncmp(value,"chi"   ,3) == 0) svga_type = 3;
  713.          if (strncmp(value,"eve"   ,3) == 0) svga_type = 4;
  714.          if (strncmp(value,"gen"   ,3) == 0) svga_type = 5;
  715.          if (strncmp(value,"ncr"   ,3) == 0) svga_type = 6;
  716.          if (strncmp(value,"oak"   ,3) == 0) svga_type = 7;
  717.          if (strncmp(value,"par"   ,3) == 0) svga_type = 8;
  718.          if (strncmp(value,"tri"   ,3) == 0) svga_type = 9;
  719.          if (strncmp(value,"tseng3",6) == 0) svga_type = 10;
  720.          if (strncmp(value,"tseng4",6) == 0) svga_type = 11;
  721.          if (strncmp(value,"vid"   ,3) == 0) svga_type = 12;
  722.          if (strncmp(value,"aheadb",6) == 0) svga_type = 13;
  723.          if (strncmp(value,"null"  ,4) == 0) svga_type = 14; /* for testing only */
  724.          if (svga_type != 0) return 3;
  725.  
  726.      video_type = 5;            /* assume video=vga */
  727.      if (strcmp(value,"egamono") == 0) {
  728.         video_type = 3;
  729.         mode7text = 1;
  730.         }
  731.      else if (strcmp(value,"hgc")) {             /* video = hgc */
  732.         video_type = 1;
  733.         mode7text = 1;
  734.         }
  735.      else if (strcmp(value,"ega"))               /* video = ega */
  736.         video_type = 3;
  737.      else if (strcmp(value,"cga"))               /* video = cga */
  738.         video_type = 2;
  739.      else if (strcmp(value,"mcga"))              /* video = mcga */
  740.         video_type = 4;
  741.      else if (strcmp(value,"vga"))               /* video = vga */
  742.         video_type = 5;
  743.      else
  744.         goto badarg;
  745.      return 3;
  746.      }
  747.  
  748.       if (strcmp(variable,"textsafe") == 0 ) {  /* textsafe==? */
  749.      if (first_init) {
  750.         if (charval == 'n') /* no */
  751.            textsafe = 2;
  752.         else if (charval == 'y') /* yes */
  753.            textsafe = 1;
  754.         else if (charval == 'b') /* bios */
  755.            textsafe = 3;
  756.         else if (charval == 's') /* save */
  757.            textsafe = 4;
  758.         else
  759.            goto badarg;
  760.         }
  761.      return 3;
  762.      }
  763.  
  764.       if (strcmp(variable, "vesadetect") == 0) {
  765.      if (yesnoval < 0) goto badarg;
  766.      vesa_detect = yesnoval;
  767.      return 3;
  768.      }
  769.  
  770.       if (strcmp(variable, "biospalette") == 0) {
  771.          if (yesnoval < 0) goto badarg;
  772.          bios_palette = yesnoval;
  773.          return 3;
  774.          }
  775.  
  776.       if (strcmp(variable, "exitnoask") == 0) {
  777.          if (yesnoval < 0) goto badarg;
  778.          escape_exit = yesnoval;
  779.          return 3;
  780.          }
  781.  
  782.       if (strcmp(variable,"fpu") == 0) {
  783.      if (strcmp(value,"iit") == 0) {
  784.         fpu = 387;
  785.         iit = 1;
  786.         return 0;
  787.         }
  788.      if (strcmp(value,"noiit") == 0) {
  789.         iit = -2;
  790.         return 0;
  791.         }
  792.      if (strcmp(value,"387") == 0) {
  793.         fpu = 387;
  794.         iit = -2;
  795.         return 0;
  796.         }
  797.      goto badarg;
  798.      }
  799.  
  800.       if (strcmp(variable,"makedoc") == 0) {
  801.      print_document(*value ? value : "fractint.doc", makedoc_msg_func, 0);
  802.      goodbye();
  803.      }
  804.  
  805.       } /* end of commands allowed only at startup */
  806.  
  807.    if (strcmp(variable,"reset") == 0) {
  808.       initvars_fractal();
  809.       return 9;
  810.       }
  811.  
  812.    if (strcmp(variable,"filename") == 0) {      /* filename=?     */
  813.       if (charval == '.') {
  814.      if (valuelen > 4) goto badarg;
  815.      gifmask[0] = '*';
  816.      gifmask[1] = 0;
  817.      strcat(gifmask,value);
  818.      return 0;
  819.      }
  820.       if (valuelen > 79) goto badarg;
  821.       if (mode == 2 && display3d == 0) /* can't do this in @ command */
  822.      goto badarg;
  823.       strcpy(readname,value);
  824.       showfile = 0;
  825.       return 3;
  826.       }
  827.  
  828.    if (strcmp(variable,"video") == 0) {         /* video=? */
  829.       if (active_system == 0) {
  830.      if ((k = check_vidmode_keyname(value)) == 0) goto badarg;
  831.      initmode = -1;
  832.      for (i = 0; i < MAXVIDEOTABLE; ++i) {
  833.         if (videotable[i].keynum == k) {
  834.            initmode = i;
  835.            break;
  836.            }
  837.         }
  838.      if (initmode == -1) goto badarg;
  839.      }
  840.       return 3;
  841.       }
  842.  
  843.    if (strcmp(variable,"map") == 0 ) {         /* map=, set default colors */
  844.       if (valuelen > 79 || SetColorPaletteName(value) != 0) goto badarg;
  845.       mapset = 1;
  846.       strcpy(MAP_name,value);
  847.       return 0;
  848.       }
  849.  
  850.    if (strcmp(variable,"colors") == 0) {       /* colors=, set current colors */
  851.       if (parse_colors(value) < 0) goto badarg;
  852.       return 0;
  853.       }
  854.  
  855.    if (strcmp(variable, "tplus") == 0) {       /* Use the TARGA+ if found? */
  856.       if (yesnoval < 0) goto badarg;
  857.       TPlusFlag = yesnoval;
  858.       return 0;
  859.       }
  860.  
  861.    if (strcmp(variable, "noninterlaced") == 0) {
  862.       if (yesnoval < 0) goto badarg;
  863.       NonInterlaced = yesnoval;
  864.       return 0;
  865.       }
  866.  
  867.    if (strcmp(variable, "maxcolorres") == 0) { /* Change default color resolution */
  868.       if (numval == 1 || numval == 4 || numval == 8 ||
  869.             numval == 16 || numval == 24) {
  870.      MaxColorRes = numval;
  871.      return 0;
  872.      }
  873.       goto badarg;
  874.       }
  875.  
  876.    if (strcmp(variable, "pixelzoom") == 0) {
  877.       if (numval < 5)
  878.      PixelZoom = numval;
  879.       return 0;
  880.       }
  881.  
  882.    /* keep this for backward compatibility */
  883.    if (strcmp(variable,"warn") == 0 ) {         /* warn=? */
  884.       if (yesnoval < 0) goto badarg;
  885.       overwrite = yesnoval ^ 1;
  886.       return 0;
  887.       }
  888.    if (strcmp(variable,"overwrite") == 0 ) {    /* overwrite=? */
  889.       if (yesnoval < 0) goto badarg;
  890.       overwrite = yesnoval;
  891.       return 0;
  892.       }
  893.  
  894.    if (strcmp(variable,"gif87a") == 0 ) {       /* gif87a=? */
  895.       if (yesnoval < 0) goto badarg;
  896.       gif87a_flag = yesnoval;
  897.       return 0;
  898.       }
  899.  
  900.    if (strcmp(variable,"savetime") == 0) {      /* savetime=? */
  901.       initsavetime = numval;
  902.       return 0;
  903.       }
  904.  
  905.    if (strcmp(variable,"autokey") == 0) {       /* autokey=? */
  906.       if (strcmp(value,"record")==0)
  907.      slides=2;
  908.       else if (strcmp(value,"play")==0)
  909.      slides=1;
  910.       else
  911.      goto badarg;
  912.       return 0;
  913.       }
  914.  
  915.    if(strcmp(variable, "solidcore") == 0) {
  916.       SolidCore = yesnoval;
  917.       return(0);
  918.       }
  919.  
  920.    if(strcmp(variable, "antialias") == 0) {
  921.       if(numval < 0 || numval > 8)
  922.      goto badarg;
  923.       AntiAliasing = numval;
  924.       return(0);
  925.       }
  926.  
  927.    if(strcmp(variable, "transparent3d") == 0) {
  928.       Transparent3D = yesnoval;
  929.       return(0);
  930.       }
  931.  
  932.    if(strcmp(variable, "corecolor") == 0) {
  933.       if(floatparms != totparms || totparms != 3)
  934.      goto badarg;
  935.       CoreRed    = (int)floatval[0];
  936.       CoreGreen = (int)floatval[1];
  937.       CoreBlue    = (int)floatval[2];
  938.       return(0);
  939.       }
  940.  
  941.    if(strcmp(variable, "mdcorners") == 0) {
  942.       if(floatparms != totparms || totparms < 2 || totparms > 4)
  943.      goto badarg;
  944.       zzmin = floatval[0];
  945.       zzmax = floatval[1];
  946.       if(totparms >= 3)
  947.      ttmin = floatval[2];
  948.       if(totparms == 4)
  949.      ttmax = floatval[3];
  950.       return(0);
  951.       }
  952.  
  953.    if(strcmp(variable, "numframes") == 0) {
  954.       NumFrames = numval;
  955.       return(0);
  956.       }
  957.  
  958.    if (strcmp(variable,"autokeyname") == 0) {   /* autokeyname=? */
  959.       strcpy(autoname,value);
  960.       return 0;
  961.       }
  962.  
  963.    if (strcmp(variable,"type") == 0 ) {         /* type=? */
  964.       if (value[valuelen-1] == '*')
  965.      value[--valuelen] = 0;
  966.       /* kludge because type ifs3d has an asterisk in front */
  967.       if(strcmp(value,"ifs3d")==0)
  968.          value[3]=0;
  969.       for (k = 0; fractalspecific[k].name != NULL; k++)
  970.      if (strcmp(value,fractalspecific[k].name) == 0)
  971.         break;
  972.       if (fractalspecific[k].name == NULL) goto badarg;
  973.       curfractalspecific = &fractalspecific[fractype = k];
  974.       if (initcorners == 0) {
  975.      xx3rd = xxmin = curfractalspecific->xmin;
  976.      xxmax           = curfractalspecific->xmax;
  977.      yy3rd = yymin = curfractalspecific->ymin;
  978.      yymax           = curfractalspecific->ymax;
  979.      }
  980.       if (initparams == 0)
  981.      for (k = 0; k < 4; ++k) {
  982.         param[k] = curfractalspecific->paramvalue[k];
  983.         roundfloatd(¶m[k]);
  984.         }
  985.       return 1;
  986.       }
  987.  
  988.    if (strcmp(variable,"inside") == 0 ) {       /* inside=? */
  989.       if(strcmp(value,s_zmag)==0)
  990.      inside = -59;
  991.       else if(strcmp(value,s_bof60)==0)
  992.      inside = -60;
  993.       else if(strcmp(value,s_bof61)==0)
  994.      inside = -61;
  995.       else if(strncmp(value,s_epscross,3)==0)
  996.      inside = -100;
  997.       else if(strncmp(value,s_startrail,4)==0)
  998.      inside = -101;
  999.       else if(strcmp(value,s_maxiter)==0)
  1000.      inside = -1;
  1001.       else if(numval == NONNUMERIC)
  1002.      goto badarg;
  1003.       else
  1004.      inside = numval;
  1005.       return 1;
  1006.       }
  1007.    if (strcmp(variable,"fillcolor") == 0 ) {       /* fillcolor */
  1008.       if(strcmp(value,s_normal)==0)
  1009.      fillcolor = -1;
  1010.       else if(numval == NONNUMERIC)
  1011.      goto badarg;
  1012.       else
  1013.      fillcolor = numval;
  1014.       return 1;
  1015.       }
  1016.  
  1017.    if (strcmp(variable,"finattract") == 0 ) {   /* finattract=? */
  1018.       if (yesnoval < 0) goto badarg;
  1019.       finattract = yesnoval;
  1020.       return 1;
  1021.       }
  1022.  
  1023.    if (strcmp(variable,"function") == 0) {      /* function=?,? */
  1024.       k = 0;
  1025.       while (*value && k < 4) {
  1026.      if(set_trig_array(k++,value)) goto badarg;
  1027.      if ((value = strchr(value,'/')) == NULL) break;
  1028.      ++value;
  1029.      }
  1030.       return 1;
  1031.       }
  1032.  
  1033.    if (strcmp(variable,"outside") == 0 ) {      /* outside=? */
  1034.       if(strcmp(value,s_iter)==0)
  1035.      outside = -1;
  1036.       if(strcmp(value,s_real)==0)
  1037.      outside = -2;
  1038.       else if(strcmp(value,s_imag)==0)
  1039.      outside = -3;
  1040.       else if(strcmp(value,s_mult)==0)
  1041.      outside = -4;
  1042.       else if(strcmp(value,s_sum)==0)
  1043.      outside = -5;
  1044.  
  1045.       else if(numval == NONNUMERIC)
  1046.      goto badarg;
  1047.       else if(numval < -5 || numval > 255) goto badarg;
  1048.       else outside = numval;
  1049.       return 1;
  1050.       }
  1051.  
  1052.    if (strcmp(variable,s_maxiter) == 0) {       /* maxiter=? */
  1053.       if (numval < 2) goto badarg;
  1054.       maxit = numval;
  1055.       return 1;
  1056.       }
  1057.  
  1058.    if (strcmp(variable,"iterincr") == 0)        /* iterincr=? */
  1059.       return 0;
  1060.  
  1061.    if (strcmp(variable,"passes") == 0) {        /* passes=? */
  1062.       if ( charval != '1' && charval != '2'
  1063.     && charval != 'g' && charval != 'b'
  1064.     && charval != 't')
  1065.      goto badarg;
  1066.       usr_stdcalcmode = charval;
  1067.       return 1;
  1068.       }
  1069.  
  1070.    if (strcmp(variable,"cyclelimit") == 0 ) {   /* cyclelimit=? */
  1071.       if (numval <= 1 || numval > 256) goto badarg;
  1072.       initcyclelimit = numval;
  1073.       return 0;
  1074.       }
  1075.  
  1076.    if (strcmp(variable,"cyclerange") == 0) {
  1077.       if (totparms < 2) intval[1] = 255;
  1078.       if (totparms < 1) intval[0] = 1;
  1079.       if (totparms != intparms
  1080.     || intval[0] < 0 || intval[1] > 255 || intval[0] > intval[1])
  1081.      goto badarg;
  1082.       rotate_lo = intval[0];
  1083.       rotate_hi = intval[1];
  1084.       return 0;
  1085.       }
  1086.  
  1087.    if (strcmp(variable,"ranges") == 0) {
  1088.       int i,j,entries,prev;
  1089.       int tmpranges[128];
  1090.       if (totparms != intparms) goto badarg;
  1091.       entries = prev = i = 0;
  1092.       while (i < totparms) {
  1093.      if ((j = intval[i++]) < 0) { /* striping */
  1094.         if ((j = 0-j) < 1 || j >= 16384 || i >= totparms) goto badarg;
  1095.         tmpranges[entries++] = -1; /* {-1,width,limit} for striping */
  1096.         tmpranges[entries++] = j;
  1097.         j = intval[i++];
  1098.         }
  1099.      if (j < prev) goto badarg;
  1100.      tmpranges[entries++] = prev = j;
  1101.      }
  1102.       if (prev == 0) goto badarg;
  1103.       if ((ranges = (int far *)farmemalloc(2L*entries)) == NULL) {
  1104.      static char far msg[] = {"Insufficient memory for ranges="};
  1105.      stopmsg(0,msg);
  1106.      return(-1);
  1107.      }
  1108.       rangeslen = entries;
  1109.       for (i = 0; i < rangeslen; ++i)
  1110.      ranges[i] = tmpranges[i];
  1111.       return 1;
  1112.       }
  1113.  
  1114.    if (strcmp(variable,"savename") == 0) {      /* savename=? */
  1115.       if (valuelen > 79) goto badarg;
  1116.       if (first_init || mode == 2)
  1117.      strcpy(savename,value);
  1118.       return 0;
  1119.       }
  1120.  
  1121.    if (strcmp(variable,"exitmode") == 0) {      /* exitmode=? */
  1122.       sscanf(value,"%x",&numval);
  1123.       exitmode = numval;
  1124.       return 0;
  1125.       }
  1126.  
  1127.    if (strcmp(variable,"textcolors") == 0) {
  1128.       parse_textcolors(value);
  1129.       return 0;
  1130.       }
  1131.  
  1132.    if (strcmp(variable,"potential") == 0) {     /* potential=? */
  1133.       k = 0;
  1134.       while (k < 3 && *value) {
  1135.      potparam[k++] = atoi(value);
  1136.      if ((value = strchr(value,'/')) == NULL) k = 99;
  1137.      ++value;
  1138.      }
  1139.       pot16bit = 0;
  1140.       if (k < 99) {
  1141.      if (strcmp(value,"16bit")) goto badarg;
  1142.      pot16bit = 1;
  1143.      }
  1144.       return 1;
  1145.       }
  1146.  
  1147.    if (strcmp(variable,"params") == 0) {        /* params=?,? */
  1148.       if (totparms != floatparms || totparms > 4)
  1149.      goto badarg;
  1150.       for (k = 0; k < 4; ++k)
  1151.      param[k] = (k < totparms) ? floatval[k] : 0.0;
  1152.       initparams = 1;
  1153.       return 1;
  1154.       }
  1155.  
  1156.    if (strcmp(variable,"initorbit") == 0) {     /* initorbit=?,? */
  1157.       if(strcmp(value,"pixel")==0)
  1158.      useinitorbit = 2;
  1159.       else {
  1160.      if (totparms != 2 || floatparms != 2) goto badarg;
  1161.      initorbit[0] = floatval[0];
  1162.      initorbit[1] = floatval[1];
  1163.      useinitorbit = 1;
  1164.      }
  1165.       return 1;
  1166.       }
  1167.  
  1168.    if (strcmp(variable,"corners") == 0) {       /* corners=?,?,?,? */
  1169.       if (floatparms != totparms || (totparms != 4 && totparms != 6))
  1170.      goto badarg;
  1171.       usemag = 0;
  1172.       initcorners = 1;
  1173.       xx3rd = xxmin = floatval[0];
  1174.       xxmax =          floatval[1];
  1175.       yy3rd = yymin = floatval[2];
  1176.       yymax =          floatval[3];
  1177.       if (totparms == 6) {
  1178.      xx3rd =      floatval[4];
  1179.      yy3rd =      floatval[5];
  1180.      }
  1181.       return 1;
  1182.       }
  1183.  
  1184.    if (strcmp(variable,"center-mag") == 0) {    /* center-mag=?,?,? */
  1185.       double Xctr, Yctr,Magnification,Ratio,Height, Width,Radius;
  1186.       if (totparms != floatparms
  1187.     || (totparms != 0 && totparms != 3)
  1188.     || (totparms == 3 && floatval[2] <= 0.0))
  1189.      goto badarg;
  1190.       usemag = 1;
  1191.       if (totparms == 0) return 0;
  1192.       initcorners = 1;
  1193.       Xctr = floatval[0];
  1194.       Yctr = floatval[1];
  1195.       Magnification = floatval[2];
  1196.       Radius = 1.0 / Magnification;
  1197.       Ratio = .75;    /* inverse aspect ratio of screen  */
  1198.       /* calculate bounds */
  1199.       Height = 2.0 * Radius;
  1200.       Width = Height / Ratio;
  1201.       yymax = Yctr + Radius;
  1202.       yy3rd = yymin = Yctr - Radius;
  1203.       xxmax = Xctr + Width / 2.0;
  1204.       xx3rd = xxmin = Xctr - Width / 2.0;
  1205.       return 1;
  1206.       }
  1207.  
  1208.    if (strcmp(variable,"invert") == 0) {        /* invert=?,?,? */
  1209.       if (totparms != floatparms || (totparms != 1 && totparms != 3))
  1210.      goto badarg;
  1211.       invert = ((inversion[0] = floatval[0]) != 0.0) ? totparms : 0;
  1212.       if (totparms == 3) {
  1213.      inversion[1] = floatval[1];
  1214.      inversion[2] = floatval[2];
  1215.      }
  1216.       return 1;
  1217.       }
  1218.  
  1219.    if (strcmp(variable,"askvideo") == 0 ) {     /* askvideo=?   */
  1220.       if (yesnoval < 0) goto badarg;
  1221.       askvideo = yesnoval;
  1222.       return 0;
  1223.       }
  1224.  
  1225.    if (strcmp(variable,"ramvideo") == 0 )       /* ramvideo=?   */
  1226.       return 0; /* just ignore and return, for old time's sake */
  1227.  
  1228.    if (strcmp(variable,"float") == 0 ) {        /* float=? */
  1229.       if (yesnoval < 0) goto badarg;
  1230.       usr_floatflag = yesnoval;
  1231.       return 3;
  1232.       }
  1233.  
  1234.    if (strcmp(variable,"biomorph") == 0 ) {     /* biomorph=? */
  1235.       usr_biomorph = numval;
  1236.       return 1;
  1237.       }
  1238.  
  1239.    if (strcmp(variable,"orbitsave") == 0 ) {     /* orbitsave=? */
  1240.       if (yesnoval < 0) goto badarg;
  1241.       orbitsave = yesnoval;
  1242.       return 1;
  1243.       }
  1244.  
  1245.    if (strcmp(variable,"bailout") == 0 ) {      /* bailout=? */
  1246.       if (numval < 4 || numval > 32000) goto badarg;
  1247.       bailout = numval;
  1248.       return 1;
  1249.       }
  1250.  
  1251.    if (strcmp(variable,"symmetry") == 0 ) {     /* symmetry=? */
  1252.       if     (strcmp(value,"xaxis" )==0) forcesymmetry = XAXIS;
  1253.       else if(strcmp(value,"yaxis" )==0) forcesymmetry = YAXIS;
  1254.       else if(strcmp(value,"xyaxis")==0) forcesymmetry = XYAXIS;
  1255.       else if(strcmp(value,"origin")==0) forcesymmetry = ORIGIN;
  1256.       else if(strcmp(value,"pi"    )==0) forcesymmetry = PI_SYM;
  1257.       else if(strcmp(value,"none"  )==0) forcesymmetry = NOSYM;
  1258.       else goto badarg;
  1259.       return 1;
  1260.       }
  1261.  
  1262.    if (strcmp(variable,"printer") == 0 ) {      /* printer=? */
  1263.       if (parse_printer(value) < 0) goto badarg;
  1264.       return 0;
  1265.       }
  1266.  
  1267.    if (strcmp(variable,"printfile") == 0) {     /* print-to-file? SWT */
  1268.       if (valuelen > 79) goto badarg;
  1269.       Print_To_File = 1;
  1270.       strcpy(PrintName,value);
  1271.       return 0;
  1272.       }
  1273.  
  1274.    if(strcmp(variable, "colorps") == 0) {
  1275.       ColorPS = yesnoval;
  1276.       return(0);
  1277.       }
  1278.  
  1279.    if (strcmp(variable,"epsf") == 0) {          /* EPS type? SWT */
  1280.       Print_To_File = 1;
  1281.       EPSFileType = numval;
  1282.       Printer_Type = 5;
  1283.       if (strcmp(PrintName,"fract001.prn")==0)
  1284.      strcpy(PrintName,"fract001.eps");
  1285.       return 0;
  1286.       }
  1287.  
  1288.    if (strcmp(variable,"title") == 0) {         /* Printer title block? SWT */
  1289.       if (yesnoval < 0) goto badarg;
  1290.       Printer_Titleblock = yesnoval;
  1291.       return 0;
  1292.       }
  1293.  
  1294.    if (strcmp(variable,"translate") == 0) {     /* Translate color? SWT */
  1295.       Printer_ColorXlat=0;
  1296.       if (charval == 'y')
  1297.      Printer_ColorXlat=1;
  1298.       else if (numval > 1 || numval < -1)
  1299.      Printer_ColorXlat=numval;
  1300.       return 0;
  1301.       }
  1302.  
  1303.    if (strcmp(variable,"plotstyle") == 0) {     /* plot style? SWT */
  1304.       Printer_SStyle = numval;
  1305.       return 0;
  1306.       }
  1307.  
  1308.    if (strcmp(variable,"halftone") == 0) {      /* New halftoning? SWT */
  1309.       if (totparms != intparms) goto badarg;
  1310.       Printer_SetScreen=1;
  1311.       if ((totparms >  0) && ( intval[ 0] >= 0))
  1312.                       Printer_SFrequency = intval[ 0];
  1313.       if ((totparms >  1) && ( intval[ 1] >= 0))
  1314.                       Printer_SAngle     = intval[ 1];
  1315.       if ((totparms >  2) && ( intval[ 2] >= 0))
  1316.                       Printer_SStyle     = intval[ 2];
  1317.       if ((totparms >  3) && ( intval[ 3] >= 0))
  1318.                       Printer_RFrequency = intval[ 3];
  1319.       if ((totparms >  4) && ( intval[ 4] >= 0))
  1320.                       Printer_RAngle     = intval[ 4];
  1321.       if ((totparms >  5) && ( intval[ 5] >= 0))
  1322.                       Printer_RStyle     = intval[ 5];
  1323.       if ((totparms >  6) && ( intval[ 6] >= 0))
  1324.                       Printer_GFrequency = intval[ 6];
  1325.       if ((totparms >  7) && ( intval[ 7] >= 0))
  1326.                       Printer_GAngle     = intval[ 7];
  1327.       if ((totparms >  8) && ( intval[ 8] >= 0))
  1328.                       Printer_GStyle     = intval[ 8];
  1329.       if ((totparms >  9) && ( intval[ 9] >= 0))
  1330.                       Printer_BFrequency = intval[ 9];
  1331.       if ((totparms > 10) && ( intval[10] >= 0))
  1332.                       Printer_BAngle     = intval[10];
  1333.       if ((totparms > 11) && ( intval[11] >= 0))
  1334.                       Printer_BStyle     = intval[11];
  1335.       return 0;
  1336.       }
  1337.  
  1338.    if (strcmp(variable,"linefeed") == 0) {      /* Use LF for printer */
  1339.       if      (strcmp(value,"cr")   == 0) Printer_CRLF = 1;
  1340.       else if (strcmp(value,"lf")   == 0) Printer_CRLF = 2;
  1341.       else if (strcmp(value,"crlf") == 0) Printer_CRLF = 0;
  1342.       else goto badarg;
  1343.       return 0;
  1344.       }
  1345.  
  1346.    if (strcmp(variable,"comport") == 0 ) {      /* Set the COM parameters */
  1347.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1348.       switch (atoi(++value)) {
  1349.      case 110:  l = 0;   break;
  1350.      case 150:  l = 32;  break;
  1351.      case 300:  l = 64;  break;
  1352.      case 600:  l = 96;  break;
  1353.      case 1200: l = 128; break;
  1354.      case 2400: l = 160; break;
  1355.      case 4800: l = 192; break;
  1356.      case 9600:
  1357.      default:   l = 224; break;
  1358.      }
  1359.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1360.       for (k=0; k < strlen(value); k++) {
  1361.      switch (value[k]) {
  1362.         case '7':  l |= 2;  break;
  1363.         case '8':  l |= 3;  break;
  1364.         case 'o':  l |= 8;  break;
  1365.         case 'e':  l |= 24; break;
  1366.         case '2':  l |= 4;  break;
  1367.         }
  1368.      }
  1369. #ifndef WINFRACT
  1370.       _bios_serialcom(0,numval-1,l);
  1371. #endif
  1372.       return 0;
  1373.       }
  1374.  
  1375.    if (strcmp(variable,"sound") == 0 ) {        /* sound=? */
  1376.       soundflag = 0;
  1377.       if (strncmp(value,"ye",2) == 0)
  1378.      soundflag = -1;
  1379.       if (charval == 'x')
  1380.      soundflag = 1;
  1381.       if (charval == 'y')
  1382.      soundflag = 2;
  1383.       if (charval == 'z')
  1384.      soundflag = 3;
  1385.       return 0;
  1386.       }
  1387.  
  1388.    if (strcmp(variable,"hertz") == 0) {         /* Hertz=? */
  1389.       if (numval < 200 || numval > 10000) goto badarg;
  1390.       basehertz = numval;
  1391.       return 0;
  1392.       }
  1393.  
  1394.    if (strcmp(variable,"periodicity") == 0 ) {  /* periodicity=? */
  1395.       usr_periodicitycheck=1;
  1396.       if (charval == 'n')
  1397.      usr_periodicitycheck=0;
  1398.       else if (charval == 'y')
  1399.      usr_periodicitycheck=1;
  1400.       else if (charval == 's')   /* 's' for 'show' */
  1401.      usr_periodicitycheck=-1;
  1402.       else if(numval == NONNUMERIC)
  1403.      goto badarg;
  1404.       else if(numval != 0)
  1405.      usr_periodicitycheck=numval;
  1406.       return 1;
  1407.       }
  1408.  
  1409.    if (strcmp(variable,"logmap") == 0 ) {       /* logmap=? */
  1410.       if (charval == 'y')
  1411.      LogFlag = 1;                /* palette is logarithmic */
  1412.       else if (charval == 'n')
  1413.      LogFlag = 0;
  1414.       else if (charval == 'o')
  1415.      LogFlag = -1;                /* old log palette */
  1416.       else
  1417.      LogFlag = numval;
  1418.       return 1;
  1419.       }
  1420.  
  1421.    if (strcmp(variable,"debugflag") == 0
  1422.      || strcmp(variable,"debug") == 0) {        /* internal use only */
  1423.       debugflag = numval;
  1424.       timerflag = debugflag & 1;        /* separate timer flag */
  1425.       debugflag -= timerflag;
  1426.       return 0;
  1427.       }
  1428.  
  1429.    if (strcmp(variable, "rseed") == 0) {
  1430.       rseed = numval;
  1431.       rflag = 1;
  1432.       return 1;
  1433.       }
  1434.  
  1435.    if (strcmp(variable, "orbitdelay") == 0) {
  1436.       orbit_delay = numval;
  1437.       return 0;
  1438.       }
  1439.  
  1440.    if (strcmp(variable, "showdot") == 0) {
  1441.       showdot=numval;
  1442.       if(showdot<0)
  1443.          showdot=0;
  1444.       return 0;
  1445.       }
  1446.  
  1447.    if (strcmp(variable, "decomp") == 0) {
  1448.       if (totparms != intparms || totparms < 1) goto badarg;
  1449.       decomp[0] = intval[0];
  1450.       decomp[1] = 0;
  1451.       if (totparms > 1) /* backward compatibility */
  1452.      bailout = decomp[1] = intval[1];
  1453.       return 1;
  1454.       }
  1455.  
  1456.    if (strcmp(variable, "distest") == 0) {
  1457.       if (totparms != intparms || totparms < 1) goto badarg;
  1458.       usr_distest = intval[0];
  1459.       distestwidth = 71;
  1460.       if (totparms > 1)
  1461.      distestwidth = intval[1];
  1462.       return 1;
  1463.       }
  1464.  
  1465.    if (strcmp(variable,"formulafile") == 0) {   /* formulafile=? */
  1466.       if (valuelen > 79) goto badarg;
  1467.       strcpy(FormFileName,value);
  1468.       return 1;
  1469.       }
  1470.  
  1471.    if (strcmp(variable,"formulaname") == 0) {   /* formulaname=? */
  1472.       if (valuelen > ITEMNAMELEN) goto badarg;
  1473.       strcpy(FormName,value);
  1474.       return 1;
  1475.       }
  1476.  
  1477.    if (strcmp(variable,"lfile") == 0) {
  1478.       if (valuelen > 79) goto badarg;
  1479.       strcpy(LFileName,value);
  1480.       return 1;
  1481.       }
  1482.  
  1483.    if (strcmp(variable,"lname") == 0) {
  1484.       if (valuelen > ITEMNAMELEN) goto badarg;
  1485.       strcpy(LName,value);
  1486.       return 1;
  1487.       }
  1488.  
  1489.    if (strcmp(variable,"ifsfile") == 0) {
  1490.       if (valuelen > 79) goto badarg;
  1491.       strcpy(IFSFileName,value);
  1492.       reset_ifs_defn();
  1493.       return 1;
  1494.       }
  1495.  
  1496.    if (strcmp(variable,"ifs") == 0
  1497.      || strcmp(variable,"ifs3d") == 0) {        /* ifs3d for old time's sake */
  1498.       if (valuelen > ITEMNAMELEN) goto badarg;
  1499.       strcpy(IFSName,value);
  1500.       reset_ifs_defn();
  1501.       return 1;
  1502.       }
  1503.  
  1504.    if (strcmp(variable,"parmfile") == 0) {
  1505.       if (valuelen > 79) goto badarg;
  1506.       strcpy(CommandFile,value);
  1507.       return 0;
  1508.       }
  1509.  
  1510.    if (strcmp(variable,"stereo") == 0) {        /* stereo=? */
  1511.       if ((numval<0) || (numval>3)) goto badarg;
  1512.       glassestype = numval;
  1513.       return 3;
  1514.       }
  1515.  
  1516.    if (strcmp(variable,"rotation") == 0) {      /* rotation=?/?/? */
  1517.       if (totparms != 3 || intparms != 3) goto badarg;
  1518.       XROT = intval[0];
  1519.       YROT = intval[1];
  1520.       ZROT = intval[2];
  1521.       return 3;
  1522.       }
  1523.  
  1524.    if (strcmp(variable,"perspective") == 0) {   /* perspective=? */
  1525.       if (numval == NONNUMERIC) goto badarg;
  1526.       ZVIEWER = numval;
  1527.       return 3;
  1528.       }
  1529.  
  1530.    if (strcmp(variable,"xyshift") == 0) {       /* xyshift=?/?  */
  1531.       if (totparms != 2 || intparms != 2) goto badarg;
  1532.       XSHIFT = intval[0];
  1533.       YSHIFT = intval[1];
  1534.       return 3;
  1535.       }
  1536.  
  1537.    if (strcmp(variable,"interocular") == 0) {   /* interocular=? */
  1538.       eyeseparation = numval;
  1539.       return 3;
  1540.       }
  1541.  
  1542.    if (strcmp(variable,"converge") == 0) {      /* converg=? */
  1543.       xadjust = numval;
  1544.       return 3;
  1545.       }
  1546.  
  1547.    if (strcmp(variable,"crop") == 0) {          /* crop=? */
  1548.       if (totparms != 4 || intparms != 4
  1549.     || intval[0] < 0 || intval[0] > 100
  1550.     || intval[1] < 0 || intval[1] > 100
  1551.     || intval[2] < 0 || intval[2] > 100
  1552.     || intval[3] < 0 || intval[3] > 100)
  1553.       goto badarg;
  1554.       red_crop_left   = intval[0];
  1555.       red_crop_right  = intval[1];
  1556.       blue_crop_left  = intval[2];
  1557.       blue_crop_right = intval[3];
  1558.       return 3;
  1559.       }
  1560.  
  1561.    if (strcmp(variable,"bright") == 0) {        /* bright=? */
  1562.       if (totparms != 2 || intparms != 2) goto badarg;
  1563.       red_bright  = intval[0];
  1564.       blue_bright = intval[1];
  1565.       return 3;
  1566.       }
  1567.  
  1568.    if (strcmp(variable,"xyadjust") == 0) {      /* trans=? */
  1569.       if (totparms != 2 || intparms != 2) goto badarg;
  1570.       xtrans = intval[0];
  1571.       ytrans = intval[1];
  1572.       return 3;
  1573.       }
  1574.  
  1575.    if (strcmp(variable,"3d") == 0) {            /* 3d=?/?/..    */
  1576.       if (yesnoval < 0) goto badarg;
  1577.       display3d = yesnoval;
  1578.       initvars_3d();
  1579.       return (display3d) ? 6 : 2;
  1580.       }
  1581.  
  1582.    if (strcmp(variable,"sphere") == 0 ) {       /* sphere=? */
  1583.       if (yesnoval < 0) goto badarg;
  1584.       SPHERE = yesnoval;
  1585.       return 2;
  1586.       }
  1587.  
  1588.    if (strcmp(variable,"scalexyz") == 0) {      /* scalexyz=?/?/? */
  1589.       if (totparms < 2 || intparms != totparms) goto badarg;
  1590.       XSCALE = intval[0];
  1591.       YSCALE = intval[1];
  1592.       if (totparms > 2) ROUGH = intval[2];
  1593.       return 2;
  1594.       }
  1595.  
  1596.    /* "rough" is really scale z, but we add it here for convenience */
  1597.    if (strcmp(variable,"roughness") == 0) {     /* roughness=?  */
  1598.       ROUGH = numval;
  1599.       return 2;
  1600.       }
  1601.  
  1602.    if (strcmp(variable,"waterline") == 0) {     /* waterline=?  */
  1603.       if (numval<0) goto badarg;
  1604.       WATERLINE = numval;
  1605.       return 2;
  1606.       }
  1607.  
  1608.    if (strcmp(variable,"filltype") == 0) {      /* filltype=?   */
  1609.       if (numval < -1 || numval > 6) goto badarg;
  1610.       FILLTYPE = numval;
  1611.       return 2;
  1612.       }
  1613.  
  1614.    if (strcmp(variable,"lightsource") == 0) {   /* lightsource=?/?/? */
  1615.       if (totparms != 3 || intparms != 3) goto badarg;
  1616.       XLIGHT = intval[0];
  1617.       YLIGHT = intval[1];
  1618.       ZLIGHT = intval[2];
  1619.       return 2;
  1620.       }
  1621.  
  1622.    if (strcmp(variable,"smoothing") == 0) {     /* smoothing=?  */
  1623.       if (numval<0) goto badarg;
  1624.       LIGHTAVG = numval;
  1625.       return 2;
  1626.       }
  1627.  
  1628.    if (strcmp(variable,"latitude") == 0) {      /* latitude=?/? */
  1629.       if (totparms != 2 || intparms != 2) goto badarg;
  1630.       THETA1 = intval[0];
  1631.       THETA2 = intval[1];
  1632.       return 2;
  1633.       }
  1634.  
  1635.    if (strcmp(variable,"longitude") == 0) {     /* longitude=?/? */
  1636.       if (totparms != 2 || intparms != 2) goto badarg;
  1637.       PHI1 = intval[0];
  1638.       PHI2 = intval[1];
  1639.       return 2;
  1640.       }
  1641.  
  1642.    if (strcmp(variable,"radius") == 0) {        /* radius=? */
  1643.       if (numval < 0) goto badarg;
  1644.       RADIUS = numval;
  1645.       return 2;
  1646.       }
  1647.  
  1648.    if (strcmp(variable,"transparent") == 0) {   /* transparent? */
  1649.       if (totparms != intparms || totparms < 1) goto badarg;
  1650.       transparent[1] = transparent[0] = intval[0];
  1651.       if (totparms > 1) transparent[1] = intval[1];
  1652.       return 2;
  1653.       }
  1654.  
  1655.    if (strcmp(variable,"preview") == 0) {       /* preview? */
  1656.       if (yesnoval < 0) goto badarg;
  1657.       preview = yesnoval;
  1658.       return 2;
  1659.       }
  1660.  
  1661.    if (strcmp(variable,"showbox") == 0) {       /* showbox? */
  1662.       if (yesnoval < 0) goto badarg;
  1663.       showbox = yesnoval;
  1664.       return 2;
  1665.       }
  1666.  
  1667.    if (strcmp(variable,"coarse") == 0) {        /* coarse=? */
  1668.       if (numval < 3 || numval > 2000) goto badarg;
  1669.       previewfactor = numval;
  1670.       return 2;
  1671.       }
  1672.  
  1673.    if (strcmp(variable,"randomize") == 0) {     /* RANDOMIZE=? */
  1674.       if (numval<0 || numval>7) goto badarg;
  1675.       RANDOMIZE = numval;
  1676.       return 2;
  1677.       }
  1678.  
  1679.    if (strcmp(variable,"ambient") == 0) {       /* ambient=? */
  1680.       if (numval<0||numval>100) goto badarg;
  1681.       Ambient = numval;
  1682.       return 2;
  1683.       }
  1684.  
  1685.    if (strcmp(variable,"haze") == 0) {          /* haze=? */
  1686.       if (numval<0||numval>100) goto badarg;
  1687.       haze = numval;
  1688.       return 2;
  1689.       }
  1690.  
  1691.    if (strcmp(variable,"fullcolor") == 0) {     /* fullcolor=? */
  1692.       if (yesnoval < 0) goto badarg;
  1693.       Targa_Out = yesnoval;
  1694.       return 2;
  1695.       }
  1696.    if (strcmp(variable,"targa_out") == 0) {     /* Targa Out? */
  1697.       if (yesnoval < 0) goto badarg;
  1698.       Targa_Out = yesnoval;
  1699.       return 2;
  1700.       }
  1701.  
  1702.    if (strcmp(variable,"targa_overlay") == 0) {         /* Targa Overlay? */
  1703.       if (yesnoval < 0) goto badarg;
  1704.       Targa_Overlay = yesnoval;
  1705.       return 2;
  1706.       }
  1707.  
  1708.    if (strcmp(variable,"background") == 0) {     /* background=?/? */
  1709.       if (totparms != 3 || intparms != 3) goto badarg;
  1710.                 for (i=0;i<3;i++)
  1711.                         if (intval[i] & 0xff)
  1712.                                 goto badarg;
  1713.       back_color[0] = intval[0];
  1714.       back_color[1] = intval[1];
  1715.       back_color[2] = intval[2];
  1716.       return 2;
  1717.       }
  1718.  
  1719.    if (strcmp(variable,"lightname") == 0) {     /* lightname=?   */
  1720.       if (valuelen > 79) goto badarg;
  1721.       if (first_init || mode == 2)
  1722.      strcpy(light_name,value);
  1723.       return 0;
  1724.       }
  1725.  
  1726.    if (strcmp(variable,"ray") == 0) {           /* RAY=? */
  1727.       if (numval < 0 || numval > 6) goto badarg;
  1728.       RAY = numval;
  1729.       return 2;
  1730.       }
  1731.  
  1732.    if (strcmp(variable,"brief") == 0) {         /* BRIEF? */
  1733.       if (yesnoval < 0) goto badarg;
  1734.       BRIEF = yesnoval;
  1735.       return 2;
  1736.       }
  1737.  
  1738.  
  1739. badarg:
  1740.    argerror(curarg);
  1741.    return(-1);
  1742.  
  1743. }
  1744.  
  1745. /* Some routines broken out of above so compiler doesn't run out of heap: */
  1746.  
  1747. static void parse_textcolors(char *value)
  1748. {
  1749.    int i,j,k,hexval;
  1750.    if (strcmp(value,"mono") == 0) {
  1751.       for (k = 0; k < sizeof(txtcolor); ++k)
  1752.      txtcolor[k] = BLACK*16+WHITE;
  1753.    /* C_HELP_CURLINK = C_PROMPT_INPUT = C_CHOICE_CURRENT = C_GENERAL_INPUT
  1754.              = C_AUTHDIV1 = C_AUTHDIV2 = WHITE*16+BLACK; */
  1755.       txtcolor[6] = txtcolor[12] = txtcolor[13] = txtcolor[14] = txtcolor[20]
  1756.           = txtcolor[27] = txtcolor[28] = WHITE*16+BLACK;
  1757.       /* C_TITLE = C_HELP_HDG = C_HELP_LINK = C_PROMPT_HI = C_CHOICE_SP_KEYIN
  1758.          = C_GENERAL_HI = C_DVID_HI = C_STOP_ERR
  1759.          = C_STOP_INFO = BLACK*16+L_WHITE; */
  1760.       txtcolor[0] = txtcolor[2] = txtcolor[5] = txtcolor[11] = txtcolor[16]
  1761.           = txtcolor[17] = txtcolor[22] = txtcolor[24]
  1762.           = txtcolor[25] = BLACK*16+L_WHITE;
  1763.       }
  1764.    else {
  1765.       k = 0;
  1766.       while ( k < sizeof(txtcolor)) {
  1767.      if (*value == 0) break;
  1768.      if (*value != '/') {
  1769.         sscanf(value,"%x",&hexval);
  1770.         i = (hexval / 16) & 7;
  1771.         j = hexval & 15;
  1772.         if (i == j || (i == 0 && j == 8)) /* force contrast */
  1773.            j = 15;
  1774.         txtcolor[k] = i * 16 + j;
  1775.         if ((value = strchr(value,'/')) == NULL) break;
  1776.         }
  1777.      ++value;
  1778.      ++k;
  1779.      }
  1780.       }
  1781. }
  1782.  
  1783. static int parse_colors(char *value)
  1784. {
  1785.    int i,j,k;
  1786.    if (*value == '@') {
  1787.       if (strlen(value) > 80 || ValidateLuts(&value[1]) != 0) goto badcolor;
  1788.       if (display3d) {
  1789.         mapset = 1;
  1790.         strcpy(MAP_name,&value[1]);
  1791.         }
  1792.       else {
  1793.         strcpy(colorfile,&value[1]);
  1794.         colorstate = 2;
  1795.         }
  1796.       }
  1797.    else {
  1798.       int smooth;
  1799.       i = smooth = 0;
  1800.       while (*value) {
  1801.      if (i >= 256) goto badcolor;
  1802.      if (*value == '<') {
  1803.         if (i == 0 || smooth
  1804.           || (smooth = atoi(value+1)) < 2
  1805.           || (value = strchr(value,'>')) == NULL)
  1806.            goto badcolor;
  1807.         i += smooth;
  1808.         ++value;
  1809.         }
  1810.      else {
  1811.         for (j = 0; j < 3; ++j) {
  1812.            if ((k = *(value++)) < '0')  goto badcolor;
  1813.            else if (k <= '9')       k -= '0';
  1814.            else if (k < 'A')            goto badcolor;
  1815.            else if (k <= 'Z')       k -= ('A'-10);
  1816.            else if (k < '_' || k > 'z') goto badcolor;
  1817.            else            k -= ('_'-36);
  1818.            dacbox[i][j] = k;
  1819.            if (smooth) {
  1820.           int start,spread,cnum;
  1821.           start = i - (spread = smooth + 1);
  1822.           cnum = 0;
  1823.           if ((k - (int)dacbox[start][j]) == 0) {
  1824.              while (++cnum < spread)
  1825.             dacbox[start+cnum][j] = k;
  1826.              }
  1827.           else {
  1828.              while (++cnum < spread)
  1829.             dacbox[start+cnum][j] =
  1830.                ( cnum         *dacbox[i][j]
  1831.                + (i-(start+cnum))*dacbox[start][j]
  1832.                + spread/2 )
  1833.                / spread;
  1834.              }
  1835.           }
  1836.            }
  1837.         smooth = 0;
  1838.         ++i;
  1839.         }
  1840.      }
  1841.       if (smooth) goto badcolor;
  1842.       while (i < 256)  { /* zap unset entries */
  1843.      dacbox[i][0] = dacbox[i][1] = dacbox[i][2] = 40;
  1844.      ++i;
  1845.      }
  1846.       colorstate = 1;
  1847.       }
  1848.    colorpreloaded = 1;
  1849.    return(0);
  1850. badcolor:
  1851.    return(-1);
  1852. }
  1853.  
  1854. static int parse_printer(char *value)
  1855. {
  1856.    int k;
  1857.    if (value[0]=='h' && value[1]=='p')
  1858.       Printer_Type=1;                 /* HP LaserJet           */
  1859.    if (value[0]=='i' && value[1]=='b')
  1860.       Printer_Type=2;                 /* IBM Graphics           */
  1861.    if (value[0]=='e' && value[1]=='p')
  1862.       Printer_Type=2;                 /* Epson (model?)           */
  1863.    if (value[0]=='c' && value[1]=='o')
  1864.       Printer_Type=3;                 /* Star (Epson-Comp?) color */
  1865.    if (value[0]=='p') {
  1866.       if (value[1]=='a')
  1867.      Printer_Type=4;             /* HP Paintjet (color)    */
  1868.       if ((value[1]=='o' || value[1]=='s')) {
  1869.      Printer_Type=5;             /* PostScript  SWT */
  1870.      if (value[2]=='h' || value[2]=='l')
  1871.         Printer_Type=6;
  1872.      }
  1873.       if (value[1]=='l')
  1874.      Printer_Type=7;             /* HP Plotter (semi-color) */
  1875.       }
  1876.    if (Printer_Type == 1)             /* assume low resolution */
  1877.       Printer_Resolution = 75;
  1878.    else
  1879.       Printer_Resolution = 60;
  1880.    if (EPSFileType > 0)              /* EPS save - force type 5 */
  1881.       Printer_Type = 5;
  1882.    if ((Printer_Type == 5) || (Printer_Type == 6))
  1883.       Printer_Resolution = 150;          /* PostScript def. res. */
  1884.    if ((value=strchr(value,'/'))) {
  1885.       if ((k=atoi(++value)) >= 0) Printer_Resolution=k;
  1886.       if ((value=strchr(value,'/'))) {
  1887.      if ((k=atoi(++value))> 0) LPTNumber = k;
  1888.      if (k < 0) {
  1889.         Print_To_File = 1;
  1890.         LPTNumber = 1;
  1891.         }
  1892.      }
  1893.       }
  1894.    return(0);
  1895. }
  1896.  
  1897.  
  1898.  
  1899. static void argerror(char *badarg)    /* oops. couldn't decode this */
  1900. {
  1901.    static char far argerrmsg1[]={"\
  1902. Oops. I couldn't understand the argument:\n  "};
  1903.    static char far argerrmsg2[]={"\n\n\
  1904. (see the Startup Help screens or documentation for a complete\n\
  1905.  argument list with descriptions)"};
  1906.    char msg[300];
  1907.    if (strlen(badarg) > 70) badarg[70] = 0;
  1908.    if (active_system == 0 /* DOS */
  1909.      && first_init)      /* & this is 1st call to cmdfiles */
  1910.       sprintf(msg,"%Fs%s%Fs",argerrmsg1,badarg,argerrmsg2);
  1911.    else
  1912.       sprintf(msg,"%Fs%s",argerrmsg1,badarg);
  1913.    stopmsg(0,msg);
  1914. }
  1915.  
  1916. void set_3d_defaults()
  1917. {
  1918.    ENTER_OVLY(OVLY_CMDFILES);
  1919.    ROUGH     = 30;
  1920.    WATERLINE = 0;
  1921.    ZVIEWER   = 0;
  1922.    XSHIFT    = 0;
  1923.    YSHIFT    = 0;
  1924.    xtrans    = 0;
  1925.    ytrans    = 0;
  1926.    LIGHTAVG  = 0;
  1927.    Ambient   = 20;
  1928.    RANDOMIZE = 0;
  1929.    haze      = 0;
  1930.    back_color[0] = 51; back_color[1] = 153; back_color[2] = 200;
  1931.    if(SPHERE) {
  1932.       PHI1    =  180;
  1933.       PHI2    =  0;
  1934.       THETA1    =  -90;
  1935.       THETA2    =  90;
  1936.       RADIUS    =  100;
  1937.       FILLTYPE    = 2;
  1938.       XLIGHT    = 1;
  1939.       YLIGHT    = 1;
  1940.       ZLIGHT    = 1;
  1941.       }
  1942.    else {
  1943.       XROT    = 60;
  1944.       YROT    = 30;
  1945.       ZROT    = 0;
  1946.       XSCALE    = 90;
  1947.       YSCALE    = 90;
  1948.       FILLTYPE    = 0;
  1949.       if (active_system != 0)
  1950.      FILLTYPE = 2;
  1951.       XLIGHT    = 1;
  1952.       YLIGHT    = -1;
  1953.       ZLIGHT    = 1;
  1954.       }
  1955.     EXIT_OVLY;
  1956. }
  1957.